package tjs.study.notes.jvm.utils.jarClash;

import java.net.URL;
import java.net.URLClassLoader;

/**
 * Created by Nicky.Tang on 2021/10/19 2:28 下午
 *
 * @since 02.12.10
 */
public abstract class AbtractSelfClassLoader extends URLClassLoader {
    public AbtractSelfClassLoader(URL[] urls, ClassLoader parent) {
        super(urls, parent);
    }

    public Class<?> loadBySelfFirst(String name, boolean resolve) throws ClassNotFoundException {
        Class<?> loadedClass = this.findLoadedClass(name);
//        if("tjs.study.notes.jvm.utils.VersionObj".equals(name)){
//            loadedClass = super.loadClass(name, resolve);
//        }
        if (loadedClass == null) {
            try {
                // 优先尝试从当前路径加载
                loadedClass = this.findClass(name);
            } catch (Exception var9) {
                // 当前路径没有，再从父加载器加载
                loadedClass = super.loadClass(name, resolve);
            }
        }

        if (resolve) {
            this.resolveClass(loadedClass);
        }
        return loadedClass;
    }
}
